<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-dialog
        title="请选择打印模板"
        :visible.sync="crud.printConfig.pringDialog"
        width="30%"
        v-dialogDrag
      >
        <jPrintConfig groupId="wareFeeGoodsEnterDetail"
                      v-if="crud.printConfig.pringDialog"
                      @getPrintId="crud.detailedPrint"
                      :isPreview="crud.printConfig.isPreview"
        ></jPrintConfig>
      </el-dialog>
      <el-dialog :close-on-click-modal="false" title="选择商品"
                 destroy-on-close
                 v-dialogDrag
                 close-on-press-escape
                 :visible.sync="showQueryGoods" append-to-body width="80vw">
        <j-goods-select :buyChannel="crud.order.buyChannel" @diaLogGoodsChange="changeGoods"
                        :customerId="crud.order.customerId" :noReturnBox="false" @closeDialog="closeDialog"
                        v-if="showQueryGoods" :queryGoods.sync="queryGoods"></j-goods-select>
      </el-dialog>
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px" :rules="rules" ref="form" :model="crud.order"
                 :disabled="crud.order.orderStatus==='PASS'">
          <el-row :gutter="24">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据编码">
                <el-input v-model="crud.order.code" disabled placeholder="系统自动生成"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  v-model="crud.order.busDate"
                  type="date"
                  style="width: 100%;"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="客户名称" prop="customerId">
                <div class="flex flex-row">
                  <el-input v-model="crud.order.customerCode" disabled
                            style="width: 30%;"/>
                  <zSelect
                    :disabled="crud.order.orderStatus==='PASS'||  (isDept && !crud.order.deptId)"
                    ref="selectCustomer" isLast :value.sync="crud.order.customerId" :showName="crud.order.customerName"
                    @getChange="getInfo" url="api/dropDown/basCustomerList" :params="customerParams"
                    style="width: 70%;"/>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <!--            <el-col :span="6">-->
            <!--              <el-form-item label="单据类型" prop="sourceType">-->
            <!--                <el-select v-model="crud.order.sourceType"   style="width: 100%;" disabled class="edit-input" placeholder="请选择来源类型" >-->
            <!--                  <el-option-->
            <!--                    v-for="(item,index) in dict.t_mobile_order_source_type"-->
            <!--                    :key="index"-->
            <!--                    v-if="item.seq>0"-->
            <!--                    :label="item.label"-->
            <!--                    :value="item.value"-->
            <!--                  />-->
            <!--                </el-select>-->
            <!--              </el-form-item>-->
            <!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select
                  v-model="crud.order.orderStatus"
                  class="filter-item"
                  clearable
                  disabled
                  placeholder="状态"
                  size="small"
                  style="width: 100%;"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <!--            <el-col :span="6">-->
            <!--              <el-form-item label="采购渠道" prop="buyChannel">-->
            <!--                <el-select-->
            <!--                  v-model="crud.order.buyChannel"-->
            <!--                  class="filter-item"-->
            <!--                  clearable-->
            <!--                  placeholder="采购渠道"-->
            <!--                  size="small"-->
            <!--                  :disabled="crud.order.orderStatus==='PASS'"-->
            <!--                  style="width: 100%"-->
            <!--                >-->
            <!--                  <el-option-->
            <!--                    v-for="item in  dict.t_buy_order_buy_channel"-->
            <!--                    :key="item.id"-->
            <!--                    :label="item.label"-->
            <!--                    :value="item.value"-->
            <!--                  />-->
            <!--                </el-select>-->
            <!--              </el-form-item>-->

            <!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="出库仓库">
                <zSelect :value.sync="crud.order.warehouseId" :showName="crud.order.warehouseName" :disabled="crud.order.orderStatus==='PASS'" url="api/dropDown/basWarehouseList" @change="setDetailWarehouse"   style="width: 100%;"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="费用科目" prop="subject">
                <zSelect :value.sync="crud.order.subjectId" :showName="crud.order.subjectName"
                         :disabled="crud.order.orderStatus==='PASS'" url="api/dropDown/basSubjectList"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="部门">
                <zSelect :value.sync="crud.order.deptId" @change="deptChange" :showName="crud.order.deptName" :disabled="crud.order.orderStatus==='PASS'" url="api/dropDown/childSysDeptList"
                         style="width:  100%"/>
              </el-form-item>
<!--              <el-form-item label="部门" prop="deptId">-->
<!--                <zSelect :value.sync="crud.order.deptId" :showName="crud.order.deptName"-->
<!--                         :disabled="crud.order.orderStatus==='PASS'" url="api/dropDown/childSysDeptList"-->
<!--                         :params="{deptId:crud.order.deptId}"-->
<!--                         style="width:  100%"/>-->
<!--              </el-form-item>-->
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="人员" prop="userId">
                <zSelect :value.sync="crud.order.userId" :showName="crud.order.userName"
                         :disabled="crud.order.deptId&&crud.order.orderStatus==='PASS'" url="api/dropDown/sysUserList"
                         :params="{deptId:crud.order.deptId}"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="备注">
                <el-input v-model="crud.order.remark" :disabled="crud.order.orderStatus==='PASS'"
                          placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>

          </el-row>
<!--          <el-row>-->
            <!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
            <!--              <el-form-item label="所属二批">-->
            <!--                <z-select :value.sync="crud.order.scustomerId"-->
            <!--                          url="/api/dropDown/sCustomerList"-->
            <!--                          :showName="crud.order.scustomerName"></z-select>-->
            <!--              </el-form-item>-->
            <!--            </el-col>-->
<!--          </el-row>-->
        </el-form>
      </div>
      <!--操作栏-->
      <div>
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          :disabled="crud.order.orderStatus==='PASS'"
          type="primary"
          @click="toAdd()"
        >
          新增
        </el-button>
        <!--        <el-button-->
        <!--          slot="left"-->
        <!--          class="filter-item"-->
        <!--          size="mini"-->
        <!--          type="success"-->
        <!--          :disabled="crud.selections.length !== 1"-->
        <!--          @click="toDeatil(crud.selections)"-->
        <!--        >修改-->
        <!--        </el-button>-->
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          :disabled="crud.order.orderStatus==='PASS'"
          type="primary"
          @click="submit()"
        >
          保存
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="$route.params.id=='null'"
          :loading="crud.passLoading"
          @click="crud.doDetailPassOrReject('PASS',id)"

        >
          <!--        v-permission="permission.pass"-->
          审核
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="$route.params.id=='null'"
          @click="crud.doDetailPassOrReject('REJECT',id)"

        >
          <!--        v-permission="permission.reject"-->
          反审
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="crud.order.orderStatus!=='SAVE'"
          :loading="crud.passLoading"
          @click="crud.doDetailPassOrReject('INVALID',id)"

        >
          <!--        v-permission="permission.pass"-->
          作废
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="crud.order.orderStatus!=='INVALID'"
          @click="crud.doDetailPassOrReject('RECOVER',id)"

        >
          <!--        v-permission="permission.reject"-->
          取消作废
        </el-button>
        <el-button
          slot="right"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="warning"
          @click="crud.preView"
          :disabled="$route.params.id == 'add'"
        >打印
        </el-button>
        <el-button
          slot="right"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="warning"
          @click="crud.preView1"
          :disabled="$route.params.id == 'add'"
        >打印预览
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="$route.params.id=='null'"
          @click="handleShow"

        >
          <!--        v-permission="permission.reject"-->
          批量新增
        </el-button>
      </div>
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header" @tabSave="tabSave" @pit="pit"/>
      </el-dialog>
      <!--表单组件-->
      <!--      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"-->
      <!--                 :title="crud.status.title" width="500px">-->
      <!--        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">-->
      <!--          <el-form-item label="id">-->
      <!--            <el-input v-model="form.id" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="单据id">-->
      <!--            <el-input v-model="form.orderId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="来源明细id">-->
      <!--            <el-input v-model="form.sourceDetailId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="商品id" prop="goodsId">-->
      <!--            <el-input v-model="form.goodsId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="商品类型id">-->
      <!--            <el-input v-model="form.goodsTagId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="税种id">-->
      <!--            <el-input v-model="form.taxId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="仓库id">-->
      <!--            <el-input v-model="form.warehouseId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="库区id">-->
      <!--            <el-input v-model="form.locationId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="库位id">-->
      <!--            <el-input v-model="form.storehouseId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="批次号">-->
      <!--            <el-input v-model="form.batchNo" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="箱单位id" prop="boxUnitId">-->
      <!--            <el-input v-model="form.boxUnitId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="箱数单位计量数">-->
      <!--            <el-input v-model="form.boxUnitCount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="箱单位数量">-->
      <!--            <el-input v-model="form.boxNum" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="主单位id" prop="mainUnitId">-->
      <!--            <el-input v-model="form.mainUnitId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="主单位计量数" prop="mainUnitCount">-->
      <!--            <el-input v-model="form.mainUnitCount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="主单位数量">-->
      <!--            <el-input v-model="form.mainNum" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="数量" prop="goodsCount">-->
      <!--            <el-input v-model="form.goodsCount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="箱数">-->
      <!--            <el-input v-model="form.boxCount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="含税单价" prop="taxPrice">-->
      <!--            <el-input v-model="form.taxPrice" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="含税箱价" prop="taxBoxPrice">-->
      <!--            <el-input v-model="form.taxBoxPrice" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="含税金额">-->
      <!--            <el-input v-model="form.taxAmount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="未税单价">-->
      <!--            <el-input v-model="form.noTaxPrice" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="未税箱价">-->
      <!--            <el-input v-model="form.noTaxBoxPrice" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="未税金额">-->
      <!--            <el-input v-model="form.noTaxAmount" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="税额">-->
      <!--            <el-input v-model="form.tax" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="排序">-->
      <!--            <el-input v-model="form.seq" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="备注">-->
      <!--            <el-input v-model="form.remark" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="添加人id">-->
      <!--            <el-input v-model="form.createUserId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="添加人编码">-->
      <!--            <el-input v-model="form.createUserCode" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="添加人名称">-->
      <!--            <el-input v-model="form.createUserName" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="添加时间">-->
      <!--            <el-input v-model="form.createTime" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="修改人id">-->
      <!--            <el-input v-model="form.updateUserId" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="修改人编码">-->
      <!--            <el-input v-model="form.updateUserCode" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="修改人名称">-->
      <!--            <el-input v-model="form.updateUserName" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--          <el-form-item label="修改时间">-->
      <!--            <el-input v-model="form.updateTime" style="width: 370px;"/>-->
      <!--          </el-form-item>-->
      <!--        </el-form>-->
      <!--        <div slot="footer" class="dialog-footer">-->
      <!--          <el-button type="text" @click="crud.cancelCU">取消</el-button>-->
      <!--          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>-->
      <!--        </div>-->
      <!--      </el-dialog>-->
      <!--表格渲染-->
      <el-table ref="table" row-class-name="crud.tableRowClassName"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                highlight-current-row="highlight-current-row"
                height="500px"
                :data="crud.data"
                size="small" style="width: 100%;"
                :show-summary="true"
                :summary-method="crud.sumRow"
                sortable="custom"
                border
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @sort-change="crud.sortChange"
                @selection-change="crud.selectionChangeHandler"
                @row-dblclick="switchRowIndex">
        <el-table-column type="selection" width="55"/>
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']"/>
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 10px">{{ scope.row[`${item.prop}`] }}</span>
              <span v-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`]) }}</span>
              <span v-if="item.type == 3" style="margin-left: 10px">{{
                  getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`)
                }}</span>
              <span v-if="item.type == 4">
              <span v-if="item.prop == 'goodsName'" style="display: flex;justify-content: center;align-items: center">
                <span v-if="scope.$index !== rowIndex">{{ scope.row.goodsName }}</span>
                <el-input v-else placeholder="请输入商品" style="width: 100%" v-model="scope.row.goodsName"/>

              </span>
                <span v-if="item.prop == 'goodsTagName'"
                    style="display: flex;justify-content: center;align-items: center">
                <span v-if="scope.$index !== rowIndex">{{ scope.row.goodsTagName }}</span>
                <zSelect v-else :value.sync=" scope.row.goodsTagId" url="api/dropDown/basGoodsTagList"
                         style="width:  100%"/>
              </span>
                <span v-if="item.prop == 'boxNum'"
                      style="display: flex;justify-content: center;align-items: center">
            <span
              v-if="scope.$index !== rowIndex  || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'|| scope.row.isOne === 0">{{ scope.row.boxNum || 0 }}{{ scope.row.boxUnitName }}</span>
            <el-input v-else
                      @input.native="crud.inuptCount(scope, 'boxNum')"
                      maxlength="12"
                      v-model="scope.row.boxNum"
                      style="width:50%;float: left">
              <div slot="suffix" style="height: 100%;font-size: 15px;color: black"
                   class="flex a-item j-content">{{ scope.row.boxUnitName }}</div>
            </el-input>
              <span
                v-if="scope.$index !== rowIndex || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'|| scope.row.isOne === 0">{{
                  scope.row.mainNum || 0
                }}{{ scope.row.mainUnitName }}</span>
                <el-input v-else
                          @input.native="crud.inuptCount(scope, 'mainNum')"
                          maxlength="12"
                          v-model="scope.row.mainNum"
                          style="width:50%;float: right">
                  <div slot="suffix" style="height: 100%;font-size: 15px;color: black"
                       class="flex a-item j-content">{{ scope.row.mainUnitName }}</div>%
                </el-input>
              </span>

                <span v-if="item.prop == 'boxUnitId'" style="display: flex;justify-content: center;align-items: center">
                <span v-if="scope.$index !== rowIndex">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>
                  <el-input v-else
                            @input.native="crud.inuptCount(scope, 'boxNum')"
                            maxlength="12"
                            v-model="scope.row.boxNum"
                            style="width: 45%;float: left">
                    <template slot="append">{{ scope.row.boxUnitName }}</template>
                  </el-input>
                  <span v-if="scope.$index !== rowIndex">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>
                  <el-input v-else
                            @input.native="crud.inuptCount(scope, 'mainNum')"
                            maxlength="12"
                            v-model="scope.row.mainNum"
                            style="width: 45%;float: right">
                    <template slot="append">{{ scope.row.mainUnitName }}</template>
                  </el-input>
                 </span>
                <span v-if="item.prop == 'goodsCount'" style="display: flex;justify-content: center;align-items: center"  >
                <span v-if="scope.$index !== rowIndex">{{ scope.row.goodsCount }}</span>
                <el-input v-else
                          @input.native="crud.inuptCount(scope, 'goodsCount')"
                          oninput="value=value.replace(/[^\d^\.]/g,'')"
                          maxlength="12"
                          v-model.lazy="scope.row.goodsCount"
                          style="width: 100%"/>
              </span>
                <span v-if="item.prop == 'taxPrice'" style="display: flex;justify-content: center;align-items: center">
                <span v-if="scope.$index !== rowIndex">{{ scope.row.taxPrice }}</span>
                <el-input v-else
                          @input.native="crud.inuptCount(scope, 'taxPrice')"
                          oninput="value=value.replace(/[^\d^\.]/g,'')"
                          maxlength="12"
                          v-model.lazy="scope.row.taxPrice"
                          style="width: 100%"/>
              </span>
                <span v-if="item.prop == 'taxName'" style="display: flex;justify-content: center;align-items: center" >
                <span v-if="scope.$index !== rowIndex">{{ scope.row.taxName }}</span>
                <zSelect v-else v-model="scope.row.taxCode" class="edit-input"
                         @change="crud.setProduct($event,scope,'taxName')"
                         :value.sync="scope.row.warehouseId" url="api/dropDown/basWarehouseList"/>
              </span>
              <span v-else-if="item.prop == 'warehouseName'" style="display: flex;justify-content: center;align-items: center" >
                <span v-if="scope.$index !== rowIndex ">{{ scope.row.warehouseName }}</span>
                <zSelect v-else v-model="scope.row.warehouseId" :showName="scope.row.warehouseName" class="edit-input"         @change="crud.setProduct($event,scope,'warehouseName')" :value.sync="scope.row.warehouseId" url="api/dropDown/basWarehouseList" />
              </span>

              <span v-if="item.prop == 'storehouseName'"
                    style="display: flex;justify-content: center;align-items: center">
                            <span v-if="scope.$index !== rowIndex">{{ scope.row.storehouseName }}</span>
                <zSelect v-else :value.sync="scope.row.storehouseId"
                         @change="crud.setProduct($event,scope,'storehouseName')"
                         :params="{warehouseId:scope.row.warehouseId}" url="api/dropDown/basStorehouseList"
                         style="width: 100%;"/>
              </span>
                <span v-if="item.prop == 'remark'" style="display: flex;justify-content: center;align-items: center">
                   <span v-if="scope.$index !== rowIndex">{{ scope.row.remark }}</span>
                    <el-input v-else v-model="scope.row.remark" placeholder="请输入"></el-input>
                </span>
                <span v-if="item.prop == 'fNum'">
                <span v-if="scope.$index !== rowIndex">{{ scope.row.boxNum }}{{ scope.row.boxUnitName }}</span>
                <el-input v-else
                          @input.native="crud.inuptCount(scope, 'boxNum')"
                          maxlength="12"
                          v-model="scope.row.boxNum"
                          style="width: 45%;float: left">
                  <template slot="append">{{ scope.row.boxUnitName }}</template>
                </el-input>
                  <span v-if="scope.$index !== rowIndex">{{ scope.row.mainNum }}{{ scope.row.mainUnitName }}</span>
                  <el-input v-else
                            @input.native="crud.inuptCount(scope, 'mainNum')"
                            maxlength="12"
                            v-model="scope.row.mainNum"
                            style="width: 45%;float: right">
                    <template slot="append">{{ scope.row.mainUnitName }}</template>
                  </el-input>
              </span>
                <span v-else-if="item.prop == 'billTaxPrice'" style="display: flex;justify-content: center;align-items: center" >

                 <span v-if="scope.$index !== rowIndex  || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'|| scope.row.isOne === 0">{{ scope.row.billTaxPrice }}</span>
                    <el-input   oninput="value=value.replace(/[^\d^\.]/g,'')"
                                maxlength="12" @input="computedBill(scope.row, 'billTaxPrice')" v-else v-model="scope.row.billTaxPrice"
                                placeholder="请输入内容"
                    ></el-input>
            </span>
                <span v-else-if="item.prop == 'billTaxBoxPrice'" style="display: flex;justify-content: center;align-items: center" >
                 <span v-if="scope.$index !== rowIndex  || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'|| scope.row.isOne === 0">{{ scope.row.billTaxBoxPrice }}</span>
                    <el-input   oninput="value=value.replace(/[^\d^\.]/g,'')"
                                maxlength="12" @input="computedBill(scope.row, 'billTaxBoxPrice')" v-else v-model="scope.row.billTaxBoxPrice"
                                placeholder="请输入内容"
                    ></el-input>
            </span>
                <span v-else-if="item.prop == 'billTaxAmount'" style="display: flex;justify-content: center;align-items: center" >

                 <span v-if="scope.$index !== rowIndex  || crud.order.orderStatus==='PASS'||crud.order.orderStatus==='CLOSE'|| scope.row.isOne === 0">{{ Number(scope.row.billTaxAmount).toFixed(2) }}</span>
                    <el-input   oninput="value=value.replace(/[^\d^\.]/g,'')"
                                maxlength="12" @input="computedBill(scope.row, 'billTaxAmount')" v-else v-model="scope.row.billTaxAmount"
                                placeholder="请输入内容"
                    ></el-input>
            </span>
                <span v-else-if="item.prop == 'taxAmount'"  class="flex a-item j-content">
              <span v-if="scope.$index !== rowIndex || crud.order.isAccept === 1|| scope.row.isOne === 0"><span v-if="crud.order.type == 2">-</span>{{ scope.row.taxAmount }}</span>
                <el-input v-else         oninput="value=value.replace(/[^\d^\.]/g,'')"
                          maxlength="12"  @input.native="crud.inuptCount(scope, 'taxAmount')" v-model="scope.row.taxAmount"
                          placeholder="请输入内容">
                </el-input>
            </span>
              </span>
            </template>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" label="操作" fixed="right" width="150px" align="center">
          <template slot-scope="scope">
            <!--              <el-button-->
            <!--                type="primary"-->
            <!--                icon="el-icon-plus"-->
            <!--                circle-->
            <!--                v-if="(crud.data.length-1)==scope.$index"-->
            <!--                :disabled="crud.order.orderStatus==='PASS'"-->
            <!--                @click="crud.addRow(scope.$index)"></el-button>-->
            <!--              v-if="crud.data.length!==1"-->
            <el-button
              slot="reference" class="el-icon-delete opration_icon_btn"
              :disabled="crud.order.orderStatus==='PASS'"
              style="border: none;width: auto;height: auto"
              @click="delAddRow(scope.$index)"></el-button>
          </template>
        </el-table-column>
        <!--        <el-table-column v-if="columns.visible('id')" prop="id" label="id"/>-->
        <!--        <el-table-column v-if="columns.visible('orderId')" prop="orderId" label="单据id"/>-->
        <!--        <el-table-column v-if="columns.visible('sourceDetailId')" prop="sourceDetailId" label="来源明细id"/>-->
        <!--        <el-table-column v-if="columns.visible('goodsId')" prop="goodsId" label="商品id"/>-->
        <!--        <el-table-column v-if="columns.visible('goodsTagId')" prop="goodsTagId" label="商品类型id"/>-->
        <!--        <el-table-column v-if="columns.visible('taxId')" prop="taxId" label="税种id"/>-->
        <!--        <el-table-column v-if="columns.visible('warehouseId')" prop="warehouseId" label="仓库id"/>-->
        <!--        <el-table-column v-if="columns.visible('locationId')" prop="locationId" label="库区id"/>-->
        <!--        <el-table-column v-if="columns.visible('storehouseId')" prop="storehouseId" label="库位id"/>-->
        <!--        <el-table-column v-if="columns.visible('batchNo')" prop="batchNo" label="批次号"/>-->
        <!--        <el-table-column v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="箱单位id"/>-->
        <!--        <el-table-column v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱数单位计量数"/>-->
        <!--        <el-table-column v-if="columns.visible('boxNum')" prop="boxNum" label="箱单位数量"/>-->
        <!--        <el-table-column v-if="columns.visible('mainUnitId')" prop="mainUnitId" label="主单位id"/>-->
        <!--        <el-table-column v-if="columns.visible('mainUnitCount')" prop="mainUnitCount" label="主单位计量数"/>-->
        <!--        <el-table-column v-if="columns.visible('mainNum')" prop="mainNum" label="主单位数量"/>-->
        <!--        <el-table-column v-if="columns.visible('goodsCount')" prop="goodsCount" label="数量"/>-->
        <!--        <el-table-column v-if="columns.visible('boxCount')" prop="boxCount" label="箱数"/>-->
        <!--        <el-table-column v-if="columns.visible('taxPrice')" prop="taxPrice" label="含税单价"/>-->
        <!--        <el-table-column v-if="columns.visible('taxBoxPrice')" prop="taxBoxPrice" label="含税箱价"/>-->
        <!--        <el-table-column v-if="columns.visible('taxAmount')" prop="taxAmount" label="含税金额"/>-->
        <!--        <el-table-column v-if="columns.visible('noTaxPrice')" prop="noTaxPrice" label="未税单价"/>-->
        <!--        <el-table-column v-if="columns.visible('noTaxBoxPrice')" prop="noTaxBoxPrice" label="未税箱价"/>-->
        <!--        <el-table-column v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额"/>-->
        <!--        <el-table-column v-if="columns.visible('tax')" prop="tax" label="税额"/>-->
        <!--        <el-table-column v-if="columns.visible('seq')" prop="seq" label="排序"/>-->
        <!--        <el-table-column v-if="columns.visible('remark')" prop="remark" label="备注"/>-->
        <!--        <el-table-column v-if="columns.visible('createUserId')" prop="createUserId" label="添加人id"/>-->
        <!--        <el-table-column v-if="columns.visible('createUserCode')" prop="createUserCode" label="添加人编码"/>-->
        <!--        <el-table-column v-if="columns.visible('createUserName')" prop="createUserName" label="添加人名称"/>-->
        <!--        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.createTime) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column v-if="columns.visible('updateUserId')" prop="updateUserId" label="修改人id"/>-->
        <!--        <el-table-column v-if="columns.visible('updateUserCode')" prop="updateUserCode" label="修改人编码"/>-->
        <!--        <el-table-column v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人名称"/>-->
        <!--        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间">-->
        <!--          <template slot-scope="scope">-->
        <!--            <span>{{ parseTime(scope.row.updateTime) }}</span>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column v-permission="['admin','wareFeeGoodsEnterDetail:edit','wareFeeGoodsEnterDetail:del']"-->
        <!--                         label="操作" width="150px" align="center">-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation-->
        <!--              :data="scope.row"-->
        <!--              :permission="permission"-->
        <!--            />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
      <el-dialog
        title="批量新增"
        :visible.sync="showAddBatchDialog"
        width="60%"
        :before-close="handleClose1">
        <addBatch :showAddBatchDialog.sync="showAddBatchDialog" :list="crud.data"
                  :params="{customerId:crud.order.customerId,type:'BUY',}"
                  @change="afterChangeGoods"/>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import crudWareFeeGoodsEnter from '@/api/erp/wareFeeGoodsEnter'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {getHeaderProperties} from "../../../api/erp/headerProperties";
import addBatch from '@/components/addBatch/addBatch'
import {salesDetailKey} from "@/utils/key";
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig
  from "@/components/jTableColumnConfig/jTableColumnConfig";
import jGoodsSelect from "@/components/jGoodsSelect/jGoodsSelect";
import jDialog from "@/components/jDialog/jDialog";
import {Notification} from "element-ui";
import {get as getDictDetail} from '@/api/system/dictDetail'
import jPrintConfig from '@/components/jPrintConfig/jPrintConfig'
// crud交由presenter持有
const defaultCrud = CRUD({
  title: '费用商品入库单明细',
  url: 'api/wareFeeGoodsEnter/detail',
  // sort: 'id,desc',
  sort: 't.seq,asc',
  params() {
    const href = location.href.split('/')
    return {
      id: href[href.length - 1] == 'add' ? 0 : href[href.length - 1], page: 0, size: 999,
    }
  },
  crudMethod: {...crudWareFeeGoodsEnter}
})
const defaultForm = {
  id: null,
  orderId: null,
  sourceDetailId: null,
  goodsId: null,
  goodsTagId: null,
  taxId: null,
  warehouseId: null,
  warehouseCode: null,
  warehouseName: null,
  locationId: null,
  storehouseId: null,
  batchNo: null,
  boxUnitId: null,
  boxUnitCount: null,
  boxNum: null,
  mainUnitId: null,
  mainUnitCount: null,
  mainNum: null,
  goodsCount: null,
  boxCount: null,
  taxPrice: null,
  taxBoxPrice: null,
  taxAmount: null,
  noTaxPrice: null,
  noTaxBoxPrice: null,
  noTaxAmount: null,
  tax: null,
  seq: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null,
  customerId: null,
  customerCode: null,
  customerName: null,
}
export default {
  name: 'wareFeeGoodsEnterDetail',
  components: {
    jPrintConfig,
    jDialog,
    jGoodsSelect,
    pagination,
    crudOperation,
    rrOperation,
    udOperation,
    addBatch,
    jTableColumnConfig
  },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), salesDetailKey, tablemixins],
  dicts: ['common_order_status', 't_buy_order_buy_channel', 't_ware_other_enter_type', 't_ware_other_enter_source_type'],
  data() {
    return {
      customerParams: {
        sort: 'code asc'
      },
      showQueryGoods: false,
      isDept: false,
      queryGoods: {},
      id: null,
      showAddBatchDialog: false,
      permission: {
        add: ['admin', 'wareFeeGoodsEnterDetail:add'],
        edit: ['admin', 'wareFeeGoodsEnterDetail:edit'],
        del: ['admin', 'wareFeeGoodsEnterDetail:del'],
        import: ['admin', 'wareFeeGoodsEnterDetail:import'],
        export: ['admin', 'wareFeeGoodsEnterDetail:export'],
        copy: ['admin', 'wareFeeGoodsEnterDetail:copy'],
        upload: ['admin', 'wareFeeGoodsEnterDetail:upload'],
        download: ['admin', 'wareFeeGoodsEnterDetail:download'],
      },
      rules: {
        goodsId: [
          {required: true, message: '商品id不能为空', trigger: 'blur'}
        ],
        boxUnitId: [
          {required: true, message: '箱单位id不能为空', trigger: 'blur'}
        ],
        mainUnitId: [
          {required: true, message: '主单位id不能为空', trigger: 'blur'}
        ],
        mainUnitCount: [
          {required: true, message: '主单位计量数不能为空', trigger: 'blur'}
        ],
        goodsCount: [
          {required: true, message: '数量不能为空', trigger: 'blur'}
        ],
        taxPrice: [
          {required: true, message: '含税单价不能为空', trigger: 'blur'}
        ],
        taxBoxPrice: [
          {required: true, message: '含税箱价不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  watch: {},
  destroyed() {
    this.crud.setItemInfo("wareFeeGoodsEnterDetail_add")
  },
  activated() {
    //获取缓存
    let detailName
    if (/add$/.test(window.location.href)) {
      detailName = 'wareFeeGoodsEnter_add'
      this.isTheCache = false
      if (sessionStorage.getItem(detailName) === null) {
        this.orderInit()
        return
      } else {
        this.crud.data = []
        const _form = JSON.parse(sessionStorage.getItem('wareFeeGoodsEnter_add'))
        if (_form.id === null) {
          this.crud.order = _form
          this.crud.data = _form.detailList
        } else {
          this.crud.cleanItemInfo('wareFeeGoodsEnter_add')
          this.orderInit()
        }
        return
      }
    } else {
      // detailName = 'wareOtherEnter'+window.location.href.match(/\/\S{3,5}$/)[0].split('/')[1]
      detailName = 'wareFeeGoodsEnter' + window.location.href.split('/')[5]
    }
    this.detailName = detailName
    this.crud.data = []
    this.crud.saveFlag = true
    const _form = JSON.parse(sessionStorage.getItem(detailName))
    if (_form) {
      this.crud.order = _form
      this.crud.data = _form.detailList
      return true
    } else {
      this.crud.data = []
      return false
    }
  },
  deactivated() {
    //切换时设置缓存
    if (
      !this.isTheCache
    ) {
      this.crud.order.detailList = this.crud.data
      sessionStorage.setItem(this.detailName, JSON.stringify(this.crud.order))
      console.log(`${this.detailName}缓存设置成功`)
    }
  },
  created() {
    const data = {
      modelName: 'wareFeeGoodsEnterDetail',
      url: "api/wareFeeGoodsEnter/detail",
      userId: this.$store.state.user.user.userId,
    }
    this.crud.headerInfo = {
      code: 'wareFeeGoodsEnterDetail',
      userId: this.$store.state.user.user.userId,
      path: "api/wareFeeGoodsEnter/detail",
    }
    if (/add$/.test(window.location.href)) {
      getHeaderProperties(data).then(res => {
        this.crud.header = JSON.parse(res.data.header.content)
        this.$forceUpdate()
      }).catch(err => {
        console.log(err)
      })
    }
    if (this.$route.params.id == 'add') {
      if (this.crud.getItemInfo("wareFeeGoodsEnterDetail_add")) {
        return false
      }
      this.crud.order = {
        id: null,
        code: '',
        busDate: this.getTime(),
        // createTime: this.getTime(),
        name: '',
        userId: '',
        deptId: null,
        type: null,
        acceptDate: null,
        isContact: null,
        isAppend: null,
        orderStatus: 'SAVE',
        index: '0',
        customerId: '',
        contactName: '',
        contactPhone: '',
        startDate: null,
        endDate: null,
        remark: ''
      }
      // this.crud.data.push(JSON.parse(JSON.stringify(this.addRowData)))
    }
  },
  beforeUpdate() {
    if (this.$route.params.id != 'add') {
      this.id = this.$route.params.id
      this.query.id = this.id
      this.crud.order.id = this.id
    }
  },
  methods: {
    deptChange(e){
      if(this.isDept)this.customerParams['deptId'] = e.id
    },
    setDetailWarehouse(e) {
      if (!this.crud.order.warehouseId) {
        return
      }
      const data = this.crud.data.filter(item=>!item.warehouseId)
      for (let i of data) {
        i.warehouseId = e.id
        i.warehouseName = e.name
      }
    },
    orderInit() {
      this.crud.order = {
        id: null,
        orderId: null,
        goodsId: null,
        goodsCode: null,
        goodsName: null,
        barcode: null,
        boxBarcode: null,
        helpSign: null,
        model: null,
        goodsBrandId: null,
        goodsBrandCode: null,
        goodsBrandName: null,
        goodsTypeId: null,
        goodsTypeCode: null,
        goodsTypeName: null,
        goodsTagId: null,
        goodsTagCode: null,
        goodsTagName: null,
        taxId: null,
        taxCode: null,
        taxName: null,
        taxRate: null,
        firstUnitId: null,
        firstUnitCode: null,
        firstUnitName: null,
        firstUnitCount: null,
        effectGoodsCount: null,
        cutOffGoodsCount: null,
        taxPrice: null,
        noTaxPrice: null,
        taxBoxPrice: null,
        noTaxBoxPrice: null,
        seq: null,
        remark: null,
        createUserId: null,
        createUserCode: null,
        createUserName: null,
        createTime: null,
        updateUserId: null,
        updateUserCode: null,
        updateUserName: null,
        updateTime: null,
        scustomerId: null,
        warehouseId: null,
        warehouseCode: null,
        warehouseName: null,
        customerId: null,
        customerCode: null,
        customerName: null,
      }
      this.crud.data = []
      getDictDetail('t_sales_order_customer_is_follow_login_user_dept').then(res => {
        if (res.data.content[0].value === '1') {
          this.isDept = true
          if (this.user.deptId === 0) {
            this.$message.error('登录用户未配置部门，请先选择部门')
            return
          }
          this.crud.order.deptId = this.user.deptId
          this.customerParams['deptId'] = this.user.deptId
          this.crud.order.deptName = this.user.deptName
          if (!this.crud.order.customerId)
            this.$refs.selectCustomer.$el.getElementsByTagName('input')[0].focus()
        } else {
          this.$refs.selectCustomer.$el.getElementsByTagName('input')[0].focus()
        }
      })
    },
    handleClose(done) {
      this.dialogVisible = false
    },
    changeGoods(val) {
      this.showQueryGoods = false
      this.crud.diaLogGoodsChange(val)
      this.$refs.table.setCurrentRow(this.crud.data[this.rowIndex])
      console.log(val)
    },
    closeDialog(val) {
      this.showQueryGoods = false
    },
    handleShow() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.showAddBatchDialog = true
      })
    },
    afterChangeGoods(goods) {
      this.showAddBatchDialog = false
      //去重，已经去重
      let arr = this.crud.data.map(detail => detail.goodsId)
      let _goods = []
      let result = []
      goods.forEach(good => {
        // if(!arr.includes(goods.goodsId)){
        good.isSelected = true
        this.crud.data.push(good)
        // }
      })
      // this.calcuForm()
    },
    handleClose1(done) {
      this.showAddBatchDialog = false
    },
    toAddList() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.showAddBatchDialog = true
      })
    },
    getInfo(e) {
      this.crud.order.customerCode = e.code
      this.crud.order.warehouseId = e.warehouseId
      this.crud.order.warehouseName = e.warehouseName
      this.crud.order.deptName = e.deptName
      this.crud.order.deptId = e.deptId
      this.crud.order.userId = e.userId
      this.crud.order.userName = e.userName
      if (this.crud.data.length === 0) {
        this.crud.data.push({
          isSelected: true,
          id: null,
          orderId: null,
          goodsId: null,
          goodsCode: null,
          goodsName: null,
          barcode: null,
          boxBarcode: null,
          helpSign: null,
          model: null,
          goodsBrandId: null,
          goodsBrandCode: null,
          goodsBrandName: null,
          goodsTypeId: null,
          goodsTypeCode: null,
          goodsTypeName: null,
          goodsTagId: null,
          goodsTagCode: null,
          goodsTagName: null,
          taxId: null,
          taxCode: null,
          taxName: null,
          taxRate: null,
          firstUnitId: null,
          firstUnitCode: null,
          firstUnitName: null,
          firstUnitCount: null,
          effectGoodsCount: null,
          cutOffGoodsCount: null,
          taxPrice: null,
          noTaxPrice: null,
          taxBoxPrice: null,
          noTaxBoxPrice: null,
          seq: null,
          remark: null,
          createUserId: null,
          createUserCode: null,
          createUserName: null,
          createTime: null,
          updateUserId: null,
          updateUserCode: null,
          updateUserName: null,
          updateTime: null,
          warehouseId: null,
          warehouseCode: null,
          warehouseName: null,
          customerId: null,
          customerCode: null,
          customerName: null,
        })
      }
    },
    delAddRow(i) {
      if (this.$route.params.id !== 'add') {
        this.$confirm('此操作将直接删除此条产品记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.crud.delRow(i)
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      } else {
        this.crud.delRow(i)
      }
    },
    getValue(e, i) {
      console.log('this.crud.data', this.crud.data)
      this.crud.data[i].productName = e
      // let temp = this.crud.data[2]
      // this.crud.data[3] = temp
      this.crud.data.map(item => {
        // item.existId = 0
        // item.existNum = 0
        if (item.existBox === null) {
          item.existBox = 0
        }
        if (item.occupyBox === null) {
          item.occupyBox = 0
        }
      })
    },
    getInput(e, name, i) {
      console.log(',data.goodsName', e, name, i)
      if (this.crud.data) {
        if (e) {
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId = e
        } else {
          this.crud.data[i].goodsName = ''
          this.crud.data[i].goodsId = null
        }
      }
    },
    // 保存
    submit() {
      // var oDate1 = new Date(this.crud.order.startDate);
      // var oDate2 = new Date(this.crud.order.endDate);
      // if (oDate1.getTime() > oDate2.getTime()) {
      //   this.$message({
      //     message: '开始日期不能大于结束日期',
      //     type: 'warning'
      //   })
      //   this.crud.order.startDate = null
      //   this.crud.order.endDate = null
      //   return false
      // }
      console.log(this.crud.data)
      const ids = []
      this.crud.data.forEach((item,index)=>{
        if (!item.goodsId){
          ids.push(index)
        }
      })
      for(let i=ids.length-1;i>=0;i--){
        this.crud.data.splice(ids[i],1)
      }
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        const table_rules = [
          // {name: '数量', value: 'goodsCount'},
          // {name: '采购价', value: 'taxPrice'},
          // {name: '未税单价', value: 'noTaxPrice'},
          // {name: '含税金额', value: 'taxAmount'},
          // {name: '未税金额', value: 'noTaxAmount'}
        ]
        const result = table_rules.some(({name, value}) => {
          const rules = this.$refs.table.data.some((item, index) => {
            if (!this.tableRules((index + 1), name, item[value])) return true
          })
          if (rules) return true
        })
        console.log(3333)
        if (!result) this.save()
      })
    },
    tableRules(index, name, value) {
      if (!value) {
        Notification.error({title: '序号【' + index + '】' + name + '不能为空'})
        return false
      } else return true
    },
    getTime(date = new Date()) {
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? ('0' + m) : m;
      var d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      var h = date.getHours();
      h = h < 10 ? ('0' + h) : h;
      var minute = date.getMinutes();
      minute = minute < 10 ? ('0' + minute) : minute;
      var second = date.getSeconds();
      second = second < 10 ? ('0' + second) : second;
      // +' '+h+':'+minute+':'+second;
      return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
    },
    //保存
    save() {
      let that = this
      that.crud.loadingOpen()
      for (let i of this.crud.data) {
        if (!i.warehouseId) {
          i.warehouseId = this.crud.order.warehouseId
        }
      }
      this.crud.order.detailList = this.crud.data
      let params = this.crud.order
      console.log('======')
      console.log(params)
      crudWareFeeGoodsEnter.add(params).then(res => {
        if (res.success) {
          this.crud.order = res.data
          // this.crud.data = res.data.detailList
          let id = res.data.id
          if (this.$route.params.id == 'add') {
            this.$store.dispatch("tagsView/delView", this.$route);
            this.$router.push({params: {id}})
            this.crud.cleanItemInfo('wareFeeGoodsEnterDetail_add')
          }
          this.$message({
            message: '保存成功',
            type: 'success'
          })
          that.crud.refresh()
          that.crud.loadingClose()
        } else {
          that.crud.loadingClose()
          this.$message({
            message: res.msg,
            type: 'warning'
          })
        }

      }).catch((res) => {
        that.crud.loadingClose()
      })
    },
    // 新增
    toAdd() {

      if(!this.crud.order.customerId){
        this.$message({
          message: '请先选择供应商',
          type: 'error'
        })
        return false
      }
      // if(!this.crud.order.buyChannel){
      //   this.$message({
      //     message: '请先选择采购渠道',
      //     type: 'error'
      //   })
      //   return false
      // }
      this.crud.data.push({
        isSelected: true,
        id: null,
        orderId: null,
        goodsId: null,
        goodsCode: null,
        goodsName: null,
        barcode: null,
        boxBarcode: null,
        helpSign: null,
        model: null,
        goodsBrandId: null,
        goodsBrandCode: null,
        goodsBrandName: null,
        goodsTypeId: null,
        goodsTypeCode: null,
        goodsTypeName: null,
        goodsTagId: null,
        goodsTagCode: null,
        goodsTagName: null,
        warehouseId: null,
        warehouseCode: null,
        warehouseName: null,
        locationCode: null,
        locationName: null,
        storehouseCode: null,
        storehouseName: null,
        taxId: null,
        taxCode: null,
        taxName: null,
        taxRate: null,
        firstUnitId: null,
        firstUnitCode: null,
        firstUnitName: null,
        firstUnitCount: null,
        effectGoodsCount: null,
        cutOffGoodsCount: null,
        taxPrice: null,
        noTaxPrice: null,
        taxBoxPrice: null,
        noTaxBoxPrice: null,
        seq: null,
        remark: null,
        createUserId: null,
        createUserCode: null,
        createUserName: null,
        createTime: null,
        updateUserId: null,
        updateUserCode: null,
        updateUserName: null,
        updateTime: null,
        customerId: null,
        customerCode: null,
        customerName: null,
      })
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
